<?php
/*
	品牌代理中心
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$return['pluginset']=$this->plugin_setting('setting');
if($_RQ['op']=='main'){
	$_SESSION['forward_url']='jy_dayfee/index/';
	$return['setting']=$this->plugin_setting('page');
	set_html('title',$return['setting']['center']);
	$member=$this->get('member',array('mid'=>$_SESSION['uid']));
	$level_id=$member['level_id'];
	$member['leveltitle']=pdo_getcolumn('jy_dayfee_level',array('id'=>$level_id,'uniacid'=>$_SESSION['uniacid']),'title');
	$member['leveltitle']=$member['leveltitle']?:'默认等级';
	$basic=model('core/member')->basic($_SESSION['uid']);
	$member=array_merge($member,$basic);
	$member['member_num']=pdo_count('core_members',array('fromuser'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'id');
	$member['fromuser']=pdo_getcolumn('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'fromuser');
	if($member['fromuser']){
		$member['agent']=model('core/member')->basic($member['fromuser']);
	}else{
		$member['agent']=array('nickname'=>'总部');
	}
	$return['member']=$member;
	$return['feenum']=$this->count('commission',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'level <'=>4));
	$data=array();
	//已结算佣金
	$data['balance_total']=$this->sum('balance',array('mid'=>$_SESSION['uid']),'money');
	$data['balance_num']=$this->count('balance',array('mid'=>$_SESSION['uid']));
	//待结算佣金
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>1);
	$data['order_num']=$this->count('commission',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'id');
	/*if($this->setting['balance_day']){
		//结算天数
		$time=TIMESTAMP-intval($this->setting['balance_day'])*86400;
		$params['complete_time <']=$time;
	}*/
	$data['commission_1']=$this->sum('commission',$params,'money');
	$data['commission_total']=$this->sum('commission',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'level <'=>4),'money');
	$data['fee1']=$this->sum('commission',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'level'=>1),'money');
	$data['fee2']=$this->sum('commission',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'level'=>2),'money');
	$return['data']=$data;
	$credit_types=credit_types();
    $credit_types2=array();
    foreach($credit_types as $key=>$value){
        $fee=$member['credit'.$key];
        $credit_types2[$key]=array(
            'id'=>$key,
            'title'=>$value,
            'fee'=>$fee
        );
    }
    $return['credit_types']=$credit_types2;
	$return['xieyi']=$this->plugin_setting('apply');
	$return['jy_merch']=$this->plugin_exists('jy_merch');
	exi($return);
}

?>